﻿// <copyright file="RealmSpellExporter.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication.Export
{
    using System.IO;
    using Microsoft.LightSwitch.Framework.Client;

    public class RealmSpellExporter : IExporter<RealmSpell>
    {
        public void WriteHeaders(StreamWriter stream)
        {
            stream.WriteLine("Visibility;Name;Type;Caster Level;Holding Level;Researched by;Public Information;Owner Information;GM Information");
        }

        public void ExportData(StreamWriter stream, VisualCollection<RealmSpell> collection)
        {
            foreach (var realmSpell in collection)
            {
                stream.WriteLine(string.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8}",
                    realmSpell.Visibility,
                    realmSpell.Name != null ? realmSpell.Name.Replace(";", ".") : string.Empty,
                    realmSpell.Type,
                    realmSpell.CasterLevel != null ? realmSpell.CasterLevel.ToString() : string.Empty,
                    realmSpell.HoldingLevel,
                    realmSpell.Researcher != null ? realmSpell.Researcher.Name.Replace(";", ".") : string.Empty,
                    realmSpell.PublicInformation != null ? realmSpell.PublicInformation.Replace(";", ".") : string.Empty,
                    realmSpell.OwnerInformation != null ? realmSpell.OwnerInformation.Replace(";", ".") : string.Empty,
                    realmSpell.GMInformation != null ? realmSpell.GMInformation.Replace(";", ".") : string.Empty));
            }
        }
    }
}
